package net.joey.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileStreamDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		byte[] buffer = new byte[1024];
		try {
			FileInputStream fis = new FileInputStream("AFile.java");
			FileOutputStream fos = new FileOutputStream("CopyFileStreamAFile.cc");
			System.out.println("拷贝文件大小："+fis.available());
//			while(true){
//				if(fis.available() < 1024){
//					int remain = -1;
//					while((remain = fis.read()) != -1){
//						fos.write(remain);
//						System.out.println(remain);
//					}
//					break;
//				}else{
//					fis.read(buffer);
//					fos.write(buffer);
//					for(byte b:buffer){
//						System.out.println(b);
//					}
//				}
//			}
			int r = -1;
			while((r = fis.read()) != -1){
				fos.write(r);
				System.out.println(Integer.toHexString(r));
				System.out.println((char)r);
			}
			fis.close();
			fos.close();
			System.out.println("复制结束");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
